/**
 * 
 */
package photoPrint;

import java.util.HashMap;
import java.util.Map;

/**
 * @author filiperosa
 *
 */
public class AlbumCollection implements TADAlbumCollection {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -3981871852609636348L;
	private Map<String, TADAlbum> albums;

	/* (non-Javadoc)
	 * @see photoPrint.TADAlbumCollection#addAlbum(photoPrint.TADAlbum)
	 */
	public AlbumCollection(){
		albums = new HashMap<String,TADAlbum>();
	}
	
	public boolean addAlbum(TADAlbum album) {
		if (albums.isEmpty()||!albums.containsKey(album.getCode())){
			albums.put(album.getCode(), album);
			return true;
		}
		else if(albums.containsKey(album.getCode())){
			TADAlbum albumInMemory = albums.get(album.getCode());
			if (!albumInMemory.status()){
				albums.remove(album.getCode());
				albums.put(album.getCode(), album);
				return true;
			}
		}
		return false;
	}

	/* (non-Javadoc)
	 * @see photoPrint.TADAlbumCollection#removeAlbum(photoPrint.TADAlbum)
	 */
	public boolean removeAlbum(TADAlbum album) {
		if (!albums.isEmpty()&&albums.containsKey(album.getCode())){
			albums.remove(album.getCode());
			return true;
		}
		return false;
	}

	/* (non-Javadoc)
	 * @see photoPrint.TADAlbumCollection#getAlbum(java.lang.String)
	 */
	public TADAlbum getAlbum(String code) {
		if (!albums.isEmpty()&&albums.containsKey(code)){
			return albums.get(code);
		}
		return null;
	}

	@Override
	public boolean contains(String code) {
		if (!albums.isEmpty()&&albums.containsKey(code)){
			return true;
		}
		return false;
	}

	@Override
	public void put(String code, TADAlbum album) {
		albums.put(code, album);
	}

}
